import { Form } from "antd";
import { IForm } from "@/components";

import type { SearchParam } from "../type";
import type { FormItemConfig } from "@/components/FormItem";
import { useAppSelector } from "@/utils/hooks";
import { useState } from "react";

interface Props {
	doSearch: (param: SearchParam) => void;
}

const SearchForm: React.FC<Props> = ({ doSearch }) => {
	const [app] = useAppSelector(state => [state.app])
	const [addVisible, setAddVisible] = useState(false)
	const [form] = Form.useForm();

	const handleFinish = (value: SearchParam) => {
		const data = {
			...value
		};
		doSearch(data);
	};

	const handleClear = () => {
		form.resetFields();
	};

	const formItemsConfig: FormItemConfig[] = [
		{
			type: "input",
			formItemProps: {
				label: "系统名称",
				name: "tenantName"
			},
			childProps: {
				placeholder: "请输入系统名称"
			}
		},
		{
			type: "select",
			formItemProps: {
				label: "租户状态",
				name: "status"
			},
			childProps: {
				placeholder: "请选择租户状态",
				options: [
					{ label: "开启", value: 1 },
					{ label: "关闭", value: 0 }
				]
			}
		},
	];

	return (
		<>
			<IForm form={form} formItemsConfig={formItemsConfig} onFinish={handleFinish} onClear={handleClear}></IForm>
		</>
	);
};

export default SearchForm;
